package com.itcast.demo.tokkit;

/**
 * @author zheng.zhang
 */
public class MountainTest {
    public static void main(String[] args) {
        int[] arr = {2, 51, 12, 95, 42, 52, 76, 77, 23, 81, 71, 41, 2, 23, 43, 4, 64, 22, 71, 96, 1, 87, 51, 91, 67, 16, 58, 11, 44, 38, 63, 14, 4, 69, 88, 49, 92, 91, 9, 15, 17, 74, 21, 91, 24, 78, 62, 50, 82, 26, 53, 18, 25, 14, 94, 79, 44, 11, 36, 38, 44, 53, 9, 34, 58, 6, 50, 82, 81, 50, 36, 1, 6, 61, 9, 47, 33, 47, 84, 41, 57, 48, 73, 18};
        MountainTest test = new MountainTest();
        int num = test.solve(arr);
        System.out.println(num);
    }

    /**
     * 寻找最后的山峰
     * 输入: [2,4,1,2,7,8,4]
     * 返回值: 5
     *
     * @param a int整型一维数组
     * @return int整型
     */
    public int solve(int[] a) {
        // write code here
        for (int i = a.length - 1; i >= 1; i--) {
            if (a[i] >= a[i - 1]) {
                return i;
            }
        }
        return -1;
    }
}
